Skip to content

Conversation

@hanselip
Copy link
Member

Summary

This PR fixes issue #1338 where the application crashes when HttpResponseDecoder::processBody receives a non-JSON HTTP response (e.g., HTML from captive portals or network sign-in pages).

Changes

  • Added validation before JSON parsing in processBody method
  • Uses nlohmann::json::accept() to validate response body before attempting to parse
  • Logs an error and returns early if the response is not valid JSON, preventing crashes

Problem

When a network request returns a non-JSON response (such as HTML from a captive portal), the library attempts to parse it as JSON, causing a crash in the nlohmann::json::parse() function.

Solution

The fix adds a check using nlohmann::json::accept() which safely validates whether the response body is valid JSON before attempting to parse it. If validation fails, the function logs an error and returns early.

Testing

  • The fix uses the built-in nlohmann::json::accept() method which is designed for safe validation
  • The try-catch block still provides additional protection for any unexpected parsing errors
  • CI tests will validate that existing functionality remains intact

Fixes #1338

Add validation before JSON parsing in processBody to prevent crashes
when receiving non-JSON HTTP responses (e.g., HTML from captive portals).
Uses nlohmann::json::accept() to validate response body before parsing.

Fixes #1338

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@hanselip hanselip requested a review from a team as a code owner January 23, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when HttpResponseDecoder::processBody doesn't get JSON response

2 participants